package com.itheima;

import java.util.ArrayList;

public class StudntDemo3 {
    public static void main(String[] args) {
        StudntDemo2 st = new StudntDemo2("张三", 17, "男");
        StudntDemo2 st1 = new StudntDemo2("李四", 18, "女");
        StudntDemo2 st2 = new StudntDemo2("王五", 20, "男");
        StudntDemo2 st3 = new StudntDemo2("赵六", 18, "女");
        StudntDemo2 st4 = new StudntDemo2("牲口", 18, "男");
        ArrayList<StudntDemo2> list = new ArrayList<>();
        list.add(st);
        list.add(st1);
        list.add(st2);
        list.add(st3);
        list.add(st4);
        ArrayList<StudntDemo2> Larr = GetStudent(list);
        for (int i = 0; i < Larr.size(); i++) {
            StudntDemo2 ra = Larr.get(i);
            System.out.println(ra.getName() + "\t" + ra.getOld() + "\t" + ra.getSex());
        }
    }

    private static ArrayList GetStudent(ArrayList<StudntDemo2> list) {
        ArrayList<StudntDemo2> Aarr = new ArrayList();
        for (int i = 0; i < list.size(); i++) {
            StudntDemo2 st = list.get(i);
            if (st.getOld() >= 18 && st.getSex().equals("男")) {
                Aarr.add(st);
            }
        }
      return Aarr;
    }
}
